module.exports = class extends think.Controller {
  __before() {
    this.adminService = think.rpc.admin;
  }
  async loginAction() {
    const username = this.trimValue('username');
    const pwd = this.trimValue('pwd');
    const platformId = this.intVal('platform_id');
    const admin = await this.adminService.queryAdminByUserName(platformId, username, {field: 'id,username,status'});
    if (think.isEmpty(admin) || think.md5(pwd) !== admin.pwd) {
      return this.fail('账号或密码错误');
    }
    if (admin.status === 0) {
      return this.fail('账号已被冻结');
    }
    // 登录成功，返回token
    return this.success(this.setLoginUser({
      id: admin.id,
      username: admin.username,
      platform_id: platformId
    }));
  }
};
